package com.jin.lazytool.customevent;

import com.jin.lazytool.componment.NumberField;
import com.jin.lazytool.entity.IEvent;
import com.jin.lazytool.entity.MouseMotionEvent;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;

public class CustomMouseMotionEvent extends CustomEvent{

    private final NumberField x = new NumberField();
    private final NumberField y = new NumberField();

    private MouseMotionEvent event;
    {
        Tooltip.install(luaButton, new Tooltip("""
                返回对象
                {
                    exeFlag: true, // 是否执行        必须返回
                    time: 0,       // 执行前等待时间    必须返回
                    x: 0,          // 鼠标坐标x
                    y: 0           // 鼠标坐标y
                }"""));
    }

    @Override
    public String getName() {
        return "移动鼠标";
    }

    @Override
    public void initAddPanel(GridPane grid) {
        grid.addRow(2,new Label("x: "),x);
        grid.addRow(3,new Label("y: "),y);
        grid.addRow(4,new Label("等待时间"),time);
        grid.addRow(5, luaButton, luaScript);
    }

    @Override
    public void initEditPanel(GridPane grid, IEvent event) {
        this.event = (MouseMotionEvent) event;
        x.setValue(this.event.getX());
        y.setValue(this.event.getY());
        time.setValue(this.event.getTime());
        luaScript.setText(this.event.getLua());
        initAddPanel(grid);
    }

    @Override
    public IEvent fullAddIEvent() {
        event = new MouseMotionEvent();
        event.setTime(time.getNullDefaultValue());
        event.setX(x.getValue());
        event.setY(y.getValue());
        event.setLua(luaScript.getText());
        return event;
    }

    @Override
    public void fullEditIEvent() {
        event.setTime(time.getNullDefaultValue());
        event.setX(x.getValue());
        event.setY(y.getValue());
        event.setLua(luaScript.getText());
    }

    @Override
    Class<? extends IEvent> eventClass() {
        return MouseMotionEvent.class;
    }
}
